package com.web.exiaodao.remote.service.impl;

import com.alibaba.fastjson.JSON;
import com.web.exiaodao.business.constant.JConstant;
import com.web.exiaodao.business.entity.ArtInformation;
import com.web.exiaodao.business.entity.AutherWorksTable;
import com.web.exiaodao.business.entity.FavoriteTable;
import com.web.exiaodao.business.repository.ArtInformationRepository;
import com.web.exiaodao.business.repository.AutherWorksTableRepository;
import com.web.exiaodao.business.repository.FavoriteTableRepository;
import com.web.exiaodao.remote.service.ApiAutherWorksTableService;
import com.web.exiaodao.remote.vo.*;
import com.web.webstart.base.constant.XaConstant;
import com.web.webstart.base.exception.BusinessException;
import com.web.webstart.base.service.impl.BaseService;
import com.web.webstart.base.util.XaUtil;
import com.web.webstart.base.util.jpa.DynamicSpecifications;
import com.web.webstart.base.util.jpa.MyPage;
import com.web.webstart.base.util.jpa.SearchFilter;
import com.web.webstart.base.util.jpa.SearchFilter.Operator;
import com.web.webstart.base.util.result.XaResult;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: zhangl
 * @times: 2016-11-03 12:03:34
 * 类的说明：前端APIAutherWorksTable接口实现类
 **/
@Service("ApiAutherWorksTableService")
@Transactional(readOnly = false)
public class ApiAutherWorksTableServiceImpl extends BaseService<AutherWorksTable> implements ApiAutherWorksTableService{

	private static final Logger LOGGER = Logger.getLogger(ApiAutherWorksTableServiceImpl.class);

	@Autowired
	AutherWorksTableRepository autherWorksTableRepository;
	@Autowired
	FavoriteTableRepository favoriteTableRepository;
	@Autowired
	ArtInformationRepository artInformationRepository;

	@Override
	public XaResult<AutherWorksTableVo> findOne(Long tId) throws BusinessException {
		AutherWorksTable obj = autherWorksTableRepository.findByIdAndStatusNot(tId,XaConstant.Status.delete);
		XaResult<AutherWorksTableVo> xr = new XaResult<AutherWorksTableVo>();
		if (XaUtil.isNotEmpty(obj)) {
			xr.setObject(JSON.parseObject(JSON.toJSONString(obj),AutherWorksTableVo.class));
			xr.getObject().setId(obj.getId());
			LOGGER.info("查询单个实体----->AutherWorksTable");
		} else {
			xr.error(XaConstant.Message.object_not_find);
			LOGGER.info(XaConstant.Message.object_not_find);
			throw new BusinessException(XaConstant.Message.object_not_find);
		}
		return xr;
	}

	@Override
	public XaResult<AutherWorksTableVo> findLastOne() throws BusinessException {
		XaResult<AutherWorksTableVo> xr = new XaResult<>();
		Map<String, SearchFilter> filters = new HashMap<>();
		filters.put("status", new SearchFilter("status", Operator.NE, XaConstant.Status.delete));
		List<AutherWorksTable> entitys = autherWorksTableRepository.findAll(DynamicSpecifications
				.bySearchFilter(filters.values(), AutherWorksTable.class), new Sort(
						new Sort.Order[]{
								new Sort.Order(Sort.Direction.DESC, "createTime"),
								new Sort.Order(Sort.Direction.DESC, "id")
						}));
		if (entitys == null || entitys.size() == 0) {
			xr.error("暂无信息");
		} else {
			xr.setObject(JSON.parseObject(JSON.toJSONString(entitys.get(0)), AutherWorksTableVo.class));
			xr.getObject().setId(entitys.get(0).getId());
			LOGGER.info("查询单个实体----->AutherWorksTable");
		}
		return xr;
	}

	@Override
	public XaResult<List<AutherWorksTableVo>> findListNEStatusByFilter(
			Integer status, Map<String, Object> filterParams, Pageable pageable)
					throws BusinessException {
		Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
		if(status == null){// 默认显示非删除的所有数据
			status = XaConstant.Status.delete;
		}
		filters.put("status", new SearchFilter("status", Operator.NE, status));
		Page<AutherWorksTable> page = autherWorksTableRepository.findAll(DynamicSpecifications
				.bySearchFilter(filters.values(), AutherWorksTable.class), pageable);
		XaResult<List<AutherWorksTableVo>> xr = new XaResult<List<AutherWorksTableVo>>();
		xr.setObject(JSON.parseArray(JSON.toJSONString(page.getContent()), AutherWorksTableVo.class));
		for(int i=0;i<page.getContent().size();i++){
			xr.getObject().get(i).setId(page.getContent().get(i).getId());
		}
		return xr;
	}

	@Override
	public XaResult<List<AutherWorksTableVo>> findListEQStatusByFilter(
			Integer status, Map<String, Object> filterParams, Pageable pageable)
					throws BusinessException {
		Map<String, SearchFilter> filters = SearchFilter.parse(filterParams);
		if(status == null){// 默认显示正常数据
			status = XaConstant.Status.valid;
		}
		filters.put("status", new SearchFilter("status", Operator.EQ, status));
		Page<AutherWorksTable> page = autherWorksTableRepository.findAll(DynamicSpecifications
				.bySearchFilter(filters.values(), AutherWorksTable.class), pageable);
		XaResult<List<AutherWorksTableVo>> xr = new XaResult<List<AutherWorksTableVo>>();
		xr.setObject(JSON.parseArray(JSON.toJSONString(page.getContent()), AutherWorksTableVo.class));
		for(int i=0;i<page.getContent().size();i++){
			xr.getObject().get(i).setId(page.getContent().get(i).getId());
		}
		return xr;
	}

	@Override
	public XaResult<AutherWorksTableVo> multiOperate(String modelIds,
			Integer status) throws BusinessException {
		XaResult<AutherWorksTableVo> xr = new XaResult<AutherWorksTableVo>();
		if(status == null){
			status = XaConstant.Status.delete;
		}
		if(modelIds != null){
			String[] ids = modelIds.split(",");
			for(String id : ids){
				AutherWorksTable obj = autherWorksTableRepository.findByIdAndStatusNot(Long.parseLong(id),status);
				if (XaUtil.isNotEmpty(obj)) {
					obj.setStatus(status);
					obj = autherWorksTableRepository.save(obj);
					xr.setObject(JSON.parseObject(JSON.toJSONString(obj), AutherWorksTableVo.class));
					xr.getObject().setId(obj.getId());
				}
			}
		}
		LOGGER.info("更改数据状态----->AutherWorksTable");
		return xr;
	}

	@Override
	public XaResult<AutherWorksTableVo> createModel(AutherWorksTable model)
			throws BusinessException {
		XaResult<AutherWorksTableVo> xr = new XaResult<AutherWorksTableVo>();
		AutherWorksTable obj = autherWorksTableRepository.save(model);
		xr.setObject(JSON.parseObject(JSON.toJSONString(obj), AutherWorksTableVo.class));
		xr.getObject().setId(obj.getId());
		LOGGER.info("新增数据成功----->AutherWorksTable");
		return xr;
	}

	@Override
	public XaResult<AutherWorksTableVo> updateModel(AutherWorksTable model)
			throws BusinessException {
		AutherWorksTable obj = autherWorksTableRepository.findOne(model.getId());
		XaResult<AutherWorksTableVo> xr = new XaResult<AutherWorksTableVo>();
		if (XaUtil.isNotEmpty(obj)) {
			obj.setWorksName(XaUtil.isNotEmpty(model.getWorksName()) ? model.getWorksName() : obj.getWorksName());
			obj.setAutherID(XaUtil.isNotEmpty(model.getAutherID()) ? model.getAutherID() : obj.getAutherID());
			obj.setWorksPrice(XaUtil.isNotEmpty(model.getWorksPrice()) ? model.getWorksPrice() : obj.getWorksPrice());
			obj.setWorksIntroduce(XaUtil.isNotEmpty(model.getWorksIntroduce()) ? model.getWorksIntroduce() : obj.getWorksIntroduce());
			obj.setWorksImgs(XaUtil.isNotEmpty(model.getWorksImgs()) ? model.getWorksImgs() : obj.getWorksImgs());
			obj.setWorksInventory(XaUtil.isNotEmpty(model.getWorksInventory()) ? model.getWorksInventory() : obj.getWorksInventory());
			obj = autherWorksTableRepository.save(obj);
			xr.setObject(JSON.parseObject(JSON.toJSONString(obj), AutherWorksTableVo.class));
			xr.getObject().setId(obj.getId());
		} else {
			xr.error(XaConstant.Message.object_not_find);
		}
		LOGGER.info("编辑数据成功----->AutherWorksTable");
		return xr;
	}

	/**
	 * 玩/艺术/学乐/达人-作品表
	 */
	@Override
	public XaResult<Page<AutherWorksTableVo>> findAutherWorksTableList(
			Integer type,Pageable pageable, AutherWorksTableVo autherWorksTableVo)
					throws BusinessException {
		XaResult<Page<AutherWorksTableVo>> xr=new XaResult<Page<AutherWorksTableVo>>();
		List<AutherWorksTableVo> vos = new ArrayList<AutherWorksTableVo>();
		StringBuffer sql = new StringBuffer();
		StringBuffer sql1 = new StringBuffer();
		if(type == 1){//作品列表
			sql.append("SELECT a.`id`,a.`works_name`,a.`works_price`,a.`works_imgs`,ar.`author_name`,ar.`author_icon_pic`,a.`create_time`,a.sort,a.click_cont ");
			sql.append("FROM `tb_xa_autherworkstable` a ");
			sql.append("LEFT JOIN `tb_xa_artinformation` ar ON a.autherid = ar.id ");
			sql.append("WHERE a.status<>").append(XaConstant.Status.delete);
			sql.append(" and ar.status<>").append(XaConstant.Status.delete);
			sql1.append("SELECT count(*) ");
			sql1.append(" FROM `tb_xa_autherworkstable` a ");
			sql1.append("LEFT JOIN `tb_xa_artinformation` ar ON a.autherid = ar.id ");
			sql1.append("WHERE a.status<>").append(XaConstant.Status.delete);
			sql1.append(" and ar.status<>").append(XaConstant.Status.delete);
			//作品--条件
			if(XaUtil.isNotEmpty(autherWorksTableVo.getWorksName())){
				sql.append(" AND a.works_name ").append(" like '%").append(autherWorksTableVo.getWorksName()).append("%' ");
				sql1.append(" AND a.works_name ").append(" like '%").append(autherWorksTableVo.getWorksName()).append("%' ");
			}
			sql.append(" ORDER BY a.sort ASC,a.click_cont DESC,a.create_time desc");
			sql1.append(" ORDER BY a.sort ASC,a.click_cont DESC,a.create_time desc");
			List<Object[]> objs = this.query(sql.toString(), pageable.getPageNumber()*pageable.getPageSize(), pageable.getPageSize());
			for (Object[] obj : objs) {
				AutherWorksTableVo vo = new AutherWorksTableVo();
				ArtInformationVo aVo = new ArtInformationVo();
				vo.setId(Long.valueOf(obj[0].toString()));
				vo.setWorksName(XaUtil.isEmpty(obj[1])?"":obj[1].toString());
				vo.setWorksPrice(XaUtil.isEmpty(obj[2])?0:Double.valueOf(obj[2].toString()));
				if(XaUtil.isEmpty(obj[3])){
					vo.setWorksImgs1(null);
				}else{
					String imgs = XaUtil.isEmpty(obj[3])?"":obj[3].toString();
					String[] arr = imgs.split(",");
					List<String> list = java.util.Arrays.asList(arr);
					vo.setWorksImgs1(list);
				}
				aVo.setAuthorName(XaUtil.isEmpty(obj[4])?"":obj[4].toString());
				aVo.setAuthorIconPic(XaUtil.isEmpty(obj[5])?"":obj[5].toString());
				vo.setCreateTime(XaUtil.isEmpty(obj[6])?"":obj[6].toString());
				vo.setSort(XaUtil.isEmpty(obj[7])?0:Long.valueOf(obj[7].toString()));
				vo.setClickCont(XaUtil.isEmpty(obj[8])?0:Long.valueOf(obj[8].toString()));
				vo.setArtInformationVo(aVo);
				vos.add(vo);
			}
			List<Object[]> obj1=this.query(sql1.toString(), null, null);
			int count=Integer.parseInt(obj1.get(0)+"");	
			Page<AutherWorksTableVo> page= new MyPage<AutherWorksTableVo>(pageable.getPageNumber(),pageable.getPageSize(),vos,count);
			xr.setObject(page);
		}else{//作者列表
			sql.append("SELECT ar.id,ar.author_name,ar.author_title,ar.author_hobby,ar.author_icon_pic,ar.author_mobile,ar.create_time,ar.sort,ar.click_cont ");
			sql.append(" FROM `tb_xa_artinformation` ar ");
			sql.append(" WHERE ar.status<>").append(XaConstant.Status.delete);
			sql1.append("SELECT count(*) ");
			sql1.append(" FROM `tb_xa_artinformation` ar ");
			sql1.append(" WHERE ar.status<>").append(XaConstant.Status.delete);
			if(XaUtil.isNotEmpty(autherWorksTableVo.getArtInformationVo().getAuthorName())){
				sql.append(" AND ar.author_name ").append(" like '%").append(autherWorksTableVo.getArtInformationVo().getAuthorName()).append("%' ");
				sql1.append(" AND ar.author_name ").append(" like '%").append(autherWorksTableVo.getArtInformationVo().getAuthorName()).append("%' ");
			}
			sql.append(" ORDER BY ar.sort ASC,ar.click_cont DESC,ar.create_time desc");
			sql1.append(" ORDER BY ar.sort ASC,ar.click_cont DESC,ar.create_time desc");
			List<Object[]> objs = this.query(sql.toString(), pageable.getPageNumber()*pageable.getPageSize(), pageable.getPageSize());
			for (Object[] obj : objs) {
				AutherWorksTableVo vo = new AutherWorksTableVo();
				ArtInformationVo aVo = new ArtInformationVo();
				aVo.setId(Long.valueOf(obj[0].toString()));
				aVo.setAuthorName(XaUtil.isEmpty(obj[1])?"":obj[1].toString());
				aVo.setAuthorTitle(XaUtil.isEmpty(obj[2])?"":obj[2].toString());
				aVo.setAuthorHobby(XaUtil.isEmpty(obj[3])?"":obj[3].toString());
				aVo.setAuthorIconPic(XaUtil.isEmpty(obj[4])?"":obj[4].toString());
				aVo.setAuthorMobile(XaUtil.isEmpty(obj[5])?"":obj[5].toString());
				aVo.setCreateTime(XaUtil.isEmpty(obj[6])?"":obj[6].toString());
				aVo.setSort(XaUtil.isEmpty(obj[7])?0:Long.valueOf(obj[7].toString()));
				aVo.setClickCont(XaUtil.isEmpty(obj[8])?0:Long.valueOf(obj[8].toString()));
				vo.setArtInformationVo(aVo);
				vos.add(vo);
			}
			List<Object[]> obj1=this.query(sql1.toString(), null, null);
			int count=Integer.parseInt(obj1.get(0)+"");	
			Page<AutherWorksTableVo> page= new MyPage<AutherWorksTableVo>(pageable.getPageNumber(),pageable.getPageSize(),vos,count);
			xr.setObject(page);
		}
		return xr;
	}

	//玩乐详情
	@Override
	public XaResult<List<AutherWorksTableVo>> findAutherWorksTableById(
			Integer type,Long userId,AutherWorksTableVo autherWorksTableVo) throws BusinessException {
		StringBuffer sql = new StringBuffer();
		List<AutherWorksTableVo> vos = new ArrayList<AutherWorksTableVo>();
		AutherWorksTableVo vo = new AutherWorksTableVo();
		ArtInformationVo aVo = new ArtInformationVo();
		List<Object[]> objs = null;
		if(type == 1){//作品详情
			sql.append("SELECT a.id,a.works_name,a.works_price,a.works_introduce,a.works_imgs,a.create_time,ar.author_name,ar.`author_title`,ar.`author_hobby`,a.autherid,ar.`author_icon_pic`,a.`works_inventory`,a.works_deposit,ar.`author_mobile`,a.sort,a.click_cont  ");
			sql.append("FROM `tb_xa_autherworkstable` a ");
			sql.append("LEFT JOIN `tb_xa_artinformation` ar ON a.autherid = ar.id ");
			sql.append("WHERE a.status<>").append(XaConstant.Status.delete);
			sql.append(" and ar.status<>").append(XaConstant.Status.delete);
			sql.append(" AND a.id= ").append(autherWorksTableVo.getId()).append(" ");
			sql.append(" ORDER BY a.sort ASC,a.click_cont DESC,a.create_time desc");
			objs = this.query(sql.toString(), null, null);
			for (Object[] obj : objs) {
				vo.setId(Long.valueOf(obj[0].toString()));
				vo.setWorksName(XaUtil.isEmpty(obj[1])?"":obj[1].toString());
				vo.setWorksPrice(XaUtil.isEmpty(obj[2])?0:Double.valueOf(obj[2].toString()));
				vo.setWorksIntroduce(XaUtil.isEmpty(obj[3])?"":obj[3].toString());
				if(XaUtil.isEmpty(obj[4])){
					vo.setWorksImgs1(null);
				}else{
					String imgs = XaUtil.isEmpty(obj[4])?"":obj[4].toString();
					String[] arr = imgs.split(",");
					List<String> list = java.util.Arrays.asList(arr);
					vo.setWorksImgs1(list);
				}
				vo.setCreateTime(XaUtil.isEmpty(obj[5])?"":obj[5].toString());
				aVo.setAuthorName(XaUtil.isEmpty(obj[6])?"":obj[6].toString());
				aVo.setAuthorTitle(XaUtil.isEmpty(obj[7])?"":obj[7].toString());
				aVo.setAuthorHobby(XaUtil.isEmpty(obj[8])?"":obj[8].toString());
				vo.setAutherID(XaUtil.isEmpty(obj[9])?0:Long.valueOf(obj[9].toString()));
				aVo.setAuthorIconPic(XaUtil.isEmpty(obj[10])?"":obj[10].toString());
				vo.setWorksInventory(XaUtil.isEmpty(obj[11])?0:Long.valueOf(obj[11].toString()));
				vo.setWorksDeposit(XaUtil.isEmpty(obj[12])?0:Double.valueOf(obj[12].toString()));
				aVo.setAuthorMobile(XaUtil.isEmpty(obj[13])?"":obj[13].toString());
				vo.setSort(XaUtil.isEmpty(obj[14])?0:Long.valueOf(obj[14].toString()));
				vo.setClickCont(XaUtil.isEmpty(obj[15])?0:Long.valueOf(obj[15].toString()));
				vo.setArtInformationVo(aVo);
			}
			//点击量＋1 保存点击量
			AutherWorksTable o = autherWorksTableRepository.findByIdAndStatusNot(autherWorksTableVo.getId(), XaConstant.Status.delete);
			o.setClickCont(1 + NumberUtils.toLong(o.getClickCont()+""));
			autherWorksTableRepository.save(o);
			//点击量＋1END
			if(XaUtil.isNotEmpty(objs)){
				//查询一条评论
				StringBuffer s1 = new StringBuffer("SELECT c.`id`,u.`photo`,u.`mobile`,c.`comment_content`,c.`comment_imgs`,c.`create_time`,u.user_name,c.object_id,c.order_detail_id ");
				s1.append("FROM `tb_xa_comment` c LEFT JOIN `tb_xa_user` u ON u.`id` = c.`user_id` ");
				s1.append("WHERE comment_types =").append(JConstant.Order_CommentType.ARTWORK).append(" AND object_id = ").append(autherWorksTableVo.getId()).append(" AND c.STATUS<>").append(XaConstant.Status.delete);
				s1.append(" ORDER BY c.create_time desc");
				List<Object[]> objs1 = this.query(s1.toString(), null,null);
				CommentVo cVo = new CommentVo();
				UserVo uVo = new UserVo();
				if(XaUtil.isNotEmpty(objs1)){
					Object[] objarrs = objs1.get(0);
					cVo.setId(Long.valueOf(objarrs[0].toString()));
					uVo.setPhoto(XaUtil.isEmpty(objarrs[1])?"":objarrs[1].toString());
					uVo.setMobile(XaUtil.isEmpty(objarrs[2])?"":objarrs[2].toString());
					cVo.setComment_Content(XaUtil.isEmpty(objarrs[3])?"":objarrs[3].toString());
					cVo.setCommentImgs(XaUtil.isEmpty(objarrs[4])?"":objarrs[4].toString());
					cVo.setCreateTime(XaUtil.isEmpty(objarrs[5])?"":objarrs[5].toString());
					uVo.setUserName(XaUtil.isEmpty(objarrs[6])?"":objarrs[6].toString());
					cVo.setObjectId(XaUtil.isEmpty(objarrs[7])?0:Long.valueOf(objarrs[7].toString()));
					cVo.setOrderDetailId(XaUtil.isEmpty(objarrs[8])?"":objarrs[8].toString());
					cVo.setUserVo(uVo);
				}
				//查询一条留言
				StringBuffer s2 = new StringBuffer("SELECT m.id,u.`photo`,u.`mobile`,m.leave_message_content,m.create_time,w.works_name,u.user_name " );
				s2.append("FROM `tb_xa_autherleavemessage` m LEFT JOIN `tb_xa_user` u ON u.`id` = m.`user_id` LEFT JOIN `tb_xa_autherworkstable` w ON w.id = m.worksid ");
				s2.append("WHERE m.status<>").append(XaConstant.Status.delete).append(" and m.worksid = ").append(autherWorksTableVo.getId());
				s2.append(" ORDER BY m.create_time desc");
				List<Object[]> objs2 = this.query(s2.toString(), null,null);
				AutherLeaveMessageVo mVo = new AutherLeaveMessageVo();
				UserVo uVo2 = new UserVo();
				if(XaUtil.isNotEmpty(objs2)){
					Object[] objarrs2 = objs2.get(0);
					mVo.setId(Long.valueOf(objarrs2[0].toString()));
					uVo2.setPhoto(XaUtil.isEmpty(objarrs2[1])?"":objarrs2[1].toString());
					uVo2.setMobile(XaUtil.isEmpty(objarrs2[2])?"":objarrs2[2].toString());
					mVo.setLeaveMessageContent(XaUtil.isEmpty(objarrs2[3])?"":objarrs2[3].toString());
					mVo.setCreateTime(XaUtil.isEmpty(objarrs2[4])?"":objarrs2[4].toString());
					uVo2.setUserName(XaUtil.isEmpty(objarrs2[5])?"":objarrs2[5].toString());
					mVo.setUserVo(uVo2);
				}
				//是否收藏
				FavoriteTable fobj = favoriteTableRepository.findByUserIdAndFavoriteObjectIdAndTypeAndStatusNot(userId, autherWorksTableVo.getId().toString(), Integer.valueOf(JConstant.Search_Share_FavType.ARTWORK).toString(), XaConstant.Status.delete);
				if(XaUtil.isEmpty(fobj)){
					vo.setFavorite_State(false);
				}else{
					vo.setFavorite_State(fobj.getFavoriteState());
					vo.setFavoriteID(fobj.getId());
				}
				vo.setCommentVo(cVo);
				vo.setAutherLeaveMessageVo(mVo);
			}
			
		}else{
			sql.append("SELECT ar.id,ar.author_name,ar.`author_introduce`,ar.`author_exhibition`,ar.create_time,a.works_name,a.works_imgs,ar.sort,ar.click_cont ");
			sql.append("FROM `tb_xa_autherworkstable` a ");
			sql.append("LEFT JOIN `tb_xa_artinformation` ar ON a.autherid = ar.id ");
			sql.append("WHERE a.status<>").append(XaConstant.Status.delete);
			sql.append(" and ar.status<>").append(XaConstant.Status.delete);
			sql.append(" AND a.autherid= ").append(autherWorksTableVo.getAutherID()).append(" ");
			sql.append(" ORDER BY ar.sort ASC,ar.click_cont DESC,ar.create_time desc");
			objs = this.query(sql.toString(), null, null);
			if(XaUtil.isNotEmpty(objs)){
				for (Object[] obj : objs) {
					aVo.setId(Long.valueOf(obj[0].toString()));
					aVo.setAuthorName(XaUtil.isEmpty(obj[1])?"":obj[1].toString());
					aVo.setAuthorIntroduce(XaUtil.isEmpty(obj[2])?"":obj[2].toString());
					aVo.setAuthorExhibition(XaUtil.isEmpty(obj[3])?"":obj[3].toString());
					aVo.setCreateTime(XaUtil.isEmpty(obj[4])?"":obj[4].toString());
					vo.setWorksName(XaUtil.isEmpty(obj[5])?"":obj[5].toString());
					if(XaUtil.isEmpty(obj[6])){
						vo.setWorksImgs1(null);
					}else{
						String imgs = XaUtil.isEmpty(obj[6])?"":obj[6].toString();
						String[] arr = imgs.split(",");
						List<String> list = java.util.Arrays.asList(arr);
						vo.setWorksImgs1(list);
					}
					aVo.setSort(XaUtil.isEmpty(obj[7])?0:Long.valueOf(obj[7].toString()));
					aVo.setClickCont(XaUtil.isEmpty(obj[8])?0:Long.valueOf(obj[8].toString()));
					vo.setArtInformationVo(aVo);
				}
			}else{//只返回作者详情
				ArtInformation aobj = artInformationRepository.findByIdAndStatusNot(autherWorksTableVo.getAutherID(),XaConstant.Status.delete);
				aVo.setId(aobj.getId());
				aVo.setAuthorName(XaUtil.isEmpty(aobj.getAuthorName())?"":aobj.getAuthorName());
				aVo.setAuthorIntroduce(XaUtil.isEmpty(aobj.getAuthorIntroduce())?"":aobj.getAuthorIntroduce());
				aVo.setAuthorExhibition(XaUtil.isEmpty(aobj.getAuthorExhibition())?"":aobj.getAuthorExhibition());
				aVo.setCreateTime(XaUtil.isEmpty(aobj.getCreateTime())?"":aobj.getCreateTime());
				aVo.setSort(XaUtil.isEmpty(aobj.getSort())?0:aobj.getSort());
				aVo.setClickCont(XaUtil.isEmpty(aobj.getClickCont())?0:aobj.getClickCont());
				vo.setArtInformationVo(aVo);
			}
			//点击量＋1 保存点击量
			ArtInformation o1 = artInformationRepository.findByIdAndStatusNot(autherWorksTableVo.getAutherID(), XaConstant.Status.delete);
			o1.setClickCont(1 + NumberUtils.toLong(o1.getClickCont()+""));
			artInformationRepository.save(o1);
			//点击量＋1END
		}

		vos.add(vo);
		XaResult<List<AutherWorksTableVo>> xr=new XaResult<List<AutherWorksTableVo>>();
		xr.setObject(vos);
		return xr;
	}

	//查询主要作品
	@Override
	public XaResult<List<AutherWorksTableVo>> findWorksById(Long atrId) throws BusinessException {
		XaResult<List<AutherWorksTableVo>> xr = new XaResult<List<AutherWorksTableVo>>();
		List<AutherWorksTable> objs = autherWorksTableRepository.findByAutherIDAndStatusNot(atrId, XaConstant.Status.delete);
		List<AutherWorksTableVo> vos = new ArrayList<AutherWorksTableVo>();
		for (AutherWorksTable obj : objs) {
			AutherWorksTableVo vo = new AutherWorksTableVo();
			if(XaUtil.isNotEmpty(obj)){
				if(XaUtil.isNotEmpty(obj.getWorksName())){
					vo.setId(obj.getId());
					vo.setWorksName(obj.getWorksName());
				}
				if(XaUtil.isNotEmpty(obj.getWorksImgs())){
					vo.setWorksImgs(obj.getWorksImgs().split(JConstant.SYMBOL_DOT)[0]);
				}
			}
			vos.add(vo);
		}
		xr.setObject(vos);
		return xr;

	}

}
